const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin'); // installed via npm
const { VueLoaderPlugin } = require('vue-loader')

module.exports = function (env) {
    // const isProduction = env.production
    return {
        entry: {
            // app: './src/index.js',
            main: './src/main.js'
        },
        output: {
            path: path.resolve(__dirname, 'dist'),
            filename: '[name].bundle.js',
            chunkFilename: '[name].bundle.js'
        },
        module: {
            rules: [
                {
                    test: /\.vue$/,
                    loader: 'vue-loader'
                },
            ]
        },
        plugins: [
            new HtmlWebpackPlugin({ title: 'demo', template: './src/index.html' }),
            new CleanWebpackPlugin(),
            new VueLoaderPlugin()

        ],
        resolve: {
            // extensions: [".js", ".vue"],
            alias: {
                vue$: 'vue/dist/vue.esm.js'
            },
            modules: [
                'node_modules',
            ],
        },
        devServer: {
            contentBase: path.join(__dirname, 'dist')
        },
        // optimization: {
        //     splitChunks: {
        //         chunks: 'all'
        //     }
        // }
    }

}